import java.io.Serializable;

/**
 * represents a M.U.L.E.
 * 
 * @author Sherman Mathews
 *
 */
public class Mule implements Serializable {
	
	//how much energy the MULE has
	private int energy;
	//0: food; 1: energy; 2: smithore
	private int resourceIndex; //the corresponding resource index
	private Player owner;
	/**
	 * creates an instance of a mule
	 */
	public Mule(){
		energy = 5;
	}
	
	public Mule(String type, Player owner){
		this.owner = owner;
		energy = 5;
		
		if (type.equalsIgnoreCase("food")){
			resourceIndex = 0;
		}
		
		else if (type.equalsIgnoreCase("energy")){
			resourceIndex = 1;
		}
		
		else if (type.equalsIgnoreCase("smithOre")){
			resourceIndex = 2;
		}
	}
	
	public Mule(int type, Player player) {
		this.owner = player;
		energy = 5;
		resourceIndex = type;
	}

	/**
	 * gets how much energy the mule has
	 * @return mule's energy
	 */
	public int getEnergy(){
		return energy;
	}
	
	/**
	 * whether or not the mule has energy
	 * @return true if the mule has energy
	 */
	public boolean hasEnergy(){
		return energy > 0;
	}
	
	public void produce(){
		if ( energy - 1 == -1){
			//do nothing
		}
		else{
			int amount = owner.getPlayerResource(resourceIndex) > 0? 
					owner.getPlayerResource(resourceIndex) : 0;
			owner.setPlayerResource(resourceIndex, amount + 3);
			energy -= 1;		
		}
	}
	
	public int getType() {
		return resourceIndex;
	}
	
	public String getTypeString() {
		if (resourceIndex == 0)
			return ("food");
		else if (resourceIndex == 1)
			return ("energy");
		else
			return ("smithOre");
	}
	
	public void setType(String type) {
		if (type.equalsIgnoreCase("food")){
			resourceIndex = 0;
		}
		
		else if (type.equalsIgnoreCase("energy")){
			resourceIndex = 1;
		}
		
		else if (type.equalsIgnoreCase("smithOre")){
			resourceIndex = 2;
		}
	}
}
